package uns.fit.gis.ui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import uns.fit.gis.MapDrawer;
import uns.fit.gis.Util;
import uns.fit.gis.fileio.FileWrapper;
import uns.fit.gis.i18n.LocaleManager;
import uns.fit.gis.mapdrawer.LayerConfig;
import uns.fit.gis.mapdrawer.MapCanvas;
import uns.fit.gis.mapobj.SimpleLocation;

public class LayerList extends List implements CommandListener {
	private Command backCommand;
	private Command okCommand;
	
	public LayerList() {
		super(LocaleManager.getMessage("layerlist"), List.MULTIPLE);
		
		backCommand = new Command(LocaleManager.getMessage("back"), Command.BACK, 1);
		okCommand = new Command(LocaleManager.getMessage("ok"), Command.OK, 1);
		
		addCommand(backCommand);
		addCommand(okCommand);
		setCommandListener(this);
		
		append(LocaleManager.getMessage("gasstation"), null);
		append(LocaleManager.getMessage("atm"), null);
		append(LocaleManager.getMessage("school"), null);
		append(LocaleManager.getMessage("store"), null);
		append(LocaleManager.getMessage("cafe"), null);
		append(LocaleManager.getMessage("constructionsite"), null);
		append(LocaleManager.getMessage("otherlocation"), null);
		
		setSelectedIndex(0, LayerConfig.showGasStation);
		setSelectedIndex(1, LayerConfig.showATM);
		setSelectedIndex(2, LayerConfig.showSchool);
		setSelectedIndex(3, LayerConfig.showStore);
		setSelectedIndex(4, LayerConfig.showCafe);
		setSelectedIndex(5, LayerConfig.showConstructionSite);
		setSelectedIndex(6, LayerConfig.showOtherLocation);
	}
	
	public void commandAction(Command arg0, Displayable arg1) {
		if(arg0 == backCommand)
			MapDrawer.getMidlet().showMapCanvas();
		else if(arg0 == okCommand) {
			LayerConfig.showATM = isSelected(1);
			LayerConfig.showCafe = isSelected(4);
			LayerConfig.showGasStation = isSelected(0);
			LayerConfig.showSchool = isSelected(2);
			LayerConfig.showStore = isSelected(3);
			LayerConfig.showConstructionSite = isSelected(5);
			LayerConfig.showOtherLocation = isSelected(6);
			MapDrawer.getMidlet().showMapCanvas();
		}
	}

}
